import { defineStore } from "pinia";
import  request  from "@/utils/request";
import { BannerItem,GoodItem, HotGoods, IApiRes } from '@/types/data'

export default defineStore('home',{
  persist: {
    enabled: true
    // key: 'category'
  },
  state() {
    return {
      bannerlist:[] as BannerItem[],
      newGoodList: [] as GoodItem[],
      hotGoodList: [] as HotGoods[],
    }
  },
  actions: {
    //拿轮播图数据
    async getBannerList() {
      const res = await request.get<IApiRes<BannerItem[]>>('/home/banner')
      console.log('拿轮播图数据',res);
      this.bannerlist = res.data.result
    },
        //新鲜好物
     async getNewList() {
      const res = await request.get<IApiRes<GoodItem[]>>('/home/new')
      console.log('新鲜好物',res);
      this.newGoodList = res.data.result
    },
    // 人气推荐
    async getHotList() {
      const res = await request.get<IApiRes<HotGoods[]>>('/home/hot')
      console.log('新鲜好物',res);
      this.hotGoodList = res.data.result
    },
  }
})